---@class Queue : LuaObject
local this = BaseClass('Queue')

function this:__ctor()
    self:Clear()
end

-- 末尾插入
function this:PushBack(value)
    self.last = self.last + 1
    self.queue[self.last] = value
end

-- 头部插入
function this:PushFront(value)
    self.first = self.first - 1
    self.queue[self.first] = value
end

-- 取出并移除
function this:Pop()
    local value = self:GetFirst()
    self:DelFirst()
    return value
end

-- 取出
function this:GetFirst()
    if (self.first <= self.last) then
        return self.queue[self.first]
    end
    return nil
end

function this:DelFirst()
    if (self.first <= self.last) then
        self.queue[self.first] = nil
        self.first = self.first + 1
    end
end

-- 长度
function this:Count()
    return self.last - self.first + 1
end

function this:Clear()
    self.queue = {}
    self.first = 0
    self.last = -1
end

Queue = this